import { createElement, LinkHTMLAttributes, type FC } from 'react';
import classNames from 'classnames';

import { breadcrumbSectionDefaultProps } from './defaultProps';
import type { BreadcrumbSectionOptions } from './type';

export interface BreadcrumbSectionProps extends BreadcrumbSectionOptions, LinkHTMLAttributes<HTMLLinkElement> {}

const BreadcrumbSection: FC<BreadcrumbSectionProps> = (props) => {
  const { className, link, active, children, forwardedRef, ...breadcrumbSectionProps } = props;

  return createElement(
    link ? 'a' : 'div',
    { ref: forwardedRef, className: classNames('section', { active }, className), ...breadcrumbSectionProps },
    children,
  );
};

BreadcrumbSection.displayName = 'BreadcrumbSection';
BreadcrumbSection.defaultProps = breadcrumbSectionDefaultProps;

export default BreadcrumbSection;
